package com.example.demo2.controller;

import com.example.demo2.generator.entity.PlanList;
import com.example.demo2.generator.entity.R;
import com.example.demo2.generator.entity.UserMessage;
import com.example.demo2.generator.service.PlanListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 计划列表(PlanList)表控制层
 *
 * @author makejava
 * @since 2024-09-26 15:07:05
 */
@Api(value = "planListController",tags = "planList测试接口")
@RestController
@RequestMapping("/planList")
public class PlanListController {
    /**
     * 服务对象
     */
    @Resource
    private PlanListService planListService;

    /**
     * 查询所用计划列表
     */
    @ApiOperation("查询所有计划列表")
    @GetMapping("/planListAll")
    public R planListAll(){
        List<PlanList> planLists = planListService.planListAll();
        return  R.ok("查询成功",planLists);
    }

//    /**
//     * 分页查询
//     *
//     * @param planList 筛选条件
//     * @param pageRequest      分页对象
//     * @return 查询结果
//     */
//    @GetMapping
//    public ResponseEntity<Page<PlanList>> queryByPage(PlanList planList, PageRequest pageRequest) {
//        return ResponseEntity.ok(this.planListService.queryByPage(planList, pageRequest));
//    }
//
    /**
     * 通过主键查询单条数据

     * @return 单条数据
     */
    @GetMapping("/queryPlanById")
    public R queryById( PlanList planList) {
        return R.ok();
    }
//
//    /**
//     * 新增数据
//     *
//     * @param planList 实体
//     * @return 新增结果
//     */
//    @PostMapping
//    public ResponseEntity<PlanList> add(PlanList planList) {
//        return ResponseEntity.ok(this.planListService.insert(planList));
//    }
//
    /**
     * 编辑数据
     *
     * @param planList 实体
     * @return 编辑结果
     */
    @ApiOperation("更新计划")
    @PostMapping("updatePlan")
    public R edit(PlanList planList) {
        System.out.println("................");
        System.out.println(planList.toString());
        return R.ok(this.planListService.update(planList));
    }

    /**
     * 删除数据
     * @return 删除是否成功
     */
    @ApiOperation("根据id删除数据")
    @PostMapping("/delById")
    public R deleteById(Integer planListId) {
        return R.ok("删除成功",this.planListService.deleteById(planListId));
    }
    @ApiOperation("批量删除计划列表")
    @PostMapping("/delsById")
    public R deletesById(@RequestBody List<PlanList> planList) {
        System.out.println(Arrays.toString(planList.toArray()));
        planListService.deletesById(planList);
        return R.ok("批量删除成功");
    }
    @ApiOperation("添加计划")
    @RequestMapping(value = "/AddPlanList",method = RequestMethod.POST)
    @ResponseBody
    public R AddPlanList(@ApiParam(name = "PlanList") @RequestBody PlanList planList){
        planListService.insert(planList);
        return R.ok("添加成功");
    }
    @ApiOperation("模糊查询")
    @RequestMapping(value = "/querybyLike",method = RequestMethod.POST)
    public R querybyLike(@ApiParam(name = "PlanList")  PlanList planList) {
        List<PlanList> planLists = planListService.queryByLike(planList);
        return R.ok("查询成功", planLists);
    }

}

